package com.example.safestop;

/**
 * @author:CrazyShaQiuShi
 * @email:3105334046@qq.com
 * @descript:
 * @version:1.0.0
 */
public class ChangeObjectThread extends Thread {
    private User u;

    public User getU() {
        return u;
    }

    public void setU(User u) {
        this.u = u;
    }

    public ChangeObjectThread(User u) {
        this.u = u;
    }

    volatile boolean stopme = false;

    public void stopMe() {
        stopme = true;
    }

    @Override
    public void run() {
        while (true) {
            if (stopme) {
                break;
            }
            synchronized (u) {
                int v = (int) (System.currentTimeMillis() / 1000);
                u.setId(v);
                try {
                    Thread.sleep(100);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                u.setName(String.valueOf(v));
            }
            Thread.yield();
        }
    }
}
